<?php

$this->session->set_flashdata('num',10);
?>
<script type="text/javascript">
function prueba(){
var anos; 
  var num = $("#fecha2").val().substring(0,2);
 return anos =  $("#fecha2").val().substring(6,10)+','+num+','+$("#fecha2").val().substring(3,5);
   	
} 
</script>
<div id="error"><?php echo @$mensage;
     $var = site_url().'/trancrearcompania/data/r1';
    ?></div>
<script language="javascript">
    // apply filters
    var applyFilter = function(){
        jQuery("#list").setGridParam({
            url: '<?php echo $var ?>',
            page:1,
            postData:{
                search: true,
                name: $('#name').val(),
                dispara_fin:$('.f_fin:checked').val()
            }
        });
    }

    jQuery(document).ready(function(){
        jQuery("#list").jqGrid({
            url: '<?php echo site_url() ?>/cipendiente/data/',
            mtype: 'POST',
            datatype: 'json',
            colNames:['ID','Referencia', 'Tipo','Etapa','Fecha E.','Dias E.','Usuario','Dias CI.'],
            colModel :[
                {name:'IdCompania', index:'IdCompania', width:5,hidden:true},
                {name:'NombreCompania', index:'NombreCompania', width:38},
                {name:'IdServicio', index:'IdServicio', width:15},
                {name:'IdEtapa', index:'IdJurisdiccion', width:10},
            	{name:'fechaEtapa', index:'FechaSysCompania', width:12},
            	{name:'diasEtapa', index:'FechaSysCompania', width:8},
            	{name:'User', index:'IdUsuario', width:20},
            	{name:'diasCI',index:'FechaSysCompania',width:8}
            			
                ],
            pager: jQuery('#pager'),
            hiddengrid: true,
            sortname: 'IdCompania',
            rowNum:200,       
            rowList:[200,250,300],
            sortorder: "DESC",
            height: '100%',
            width: '626',
            imgpath: _base_url + 'public/css/jqgrid/flex/images',
            viewrecords: true,
            multiselect: false,
            onSelectRow: function(ids) 
            {
            	if(ids != null) 
            	{
            		var rec = jQuery("#list").getRowData(ids);
            		lol=ids;
            		
            		jQuery("#list_etapas").setGridParam({url : _site_url + '/trancrearcompania/procesos_data', page : 1, mtype:'POST',postData:{id_compania:rec.IdCompania}}).setCaption("Etapas: " + rec.IdCompania).trigger('reloadGrid');
            	
            	}
            },
            adjacents: 4,
            jsonReader: { repeatitems : false, IdCompania: "0" }
        }).navGrid('#pager',{add:false,del:false,edit:false,search:false,position:"left"})
        
  
        
         .navButtonAdd('#pager',{caption:"", buttonimg: _base_url + "public/css/jqgrid/flex/images/text_columns.png", onClickButton:function(){ jQuery("#list").setColumns();} })
         
        
         .navButtonAdd('#pager',{caption:"G. INTERNO.", buttonimg: _base_url + "public/images/edit.png", onClickButton:function()
         
         { var id = jQuery('#list').getGridParam('selarrrow');
         var id=lol;
        if (id.length > 0) 
        {
                var ret = jQuery("#list").getRowData(id);
        
                window.location = _site_url + '/cipendiente/ginterno/' + ret.IdCompania;
            
        } else { jAlert('Debe seleccionar al menos una compania'); }
        return false; } })
        
        .navButtonAdd('#pager',{caption:"Detalle.", buttonimg: _base_url + "public/images/edit.png", onClickButton:function()
         
         { var id = jQuery('#list').getGridParam('selarrrow');
         var id=lol;
        if (id.length > 0) 
        {
                var ret = jQuery("#list").getRowData(id);
        
                window.location = _site_url + '/cipendiente/ginternodestalles/' + ret.IdCompania;
            
        } else { jAlert('Debe seleccionar al menos una compania'); }
        return false; } })

       
        $('#apply_filter').bind('click', applyFilter);
    });
   

 function getCheckedValue(radioObj) 
 {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
   
    
 var flAuto = true;
 var timeoutHnd; 

 function doSearch(ev)
 { 
       if(!flAuto) return; 
       // var elem = ev.target||ev.srcElement; 
       if(timeoutHnd) 
           clearTimeout(timeoutHnd); 
           timeoutHnd = setTimeout(gridReload,500); 
 } 
  
 function enableAutosubmit(state)
 { 
       flAuto = state; 
       jQuery("#submitButton").attr("disabled",state); 
 }
 
 function gridReload()
 { 
	      var us_mask =  jQuery("#search_se").val();
          var ct_mask = jQuery("#search_et").val();
          var cd_mask = jQuery("#search_cd").val(); 

           var array_search = us_mask+'-'+cd_mask+'-'+ct_mask;
       
       jQuery("#list").setGridParam({url :'<?php echo site_url() ?>/cipendiente/data/'+array_search, page : 1}).trigger('reloadGrid'); 
 }


</script>

<?php
    $usuario = $this->usuarios->LoadUsuarios();
    $estapa = $this->metapas->LoadEtapas();
?>		
<div class="table_container">

<table>
<tr><td><div id="titulo">Lista Pendiente CONTROL INTERNO</div></td></tr>

    <tr>
       <td style="background: #D9E6F0;border: 1px solid #C3AA64; height: 23px"><b>Usuario:<b/> <select id='search_se' onChange='doSearch(arguments[0]||event)' ><option></option> 
                                                                                                                                                                            <?php foreach ($usuario as $k): 
                                                                                                                                                                                       if ($k->getIdDepartamento() == 2 || $k->getIdDepartamento() == 4) {
                                                                                                                                                                                       	
                                                                                                                                                                                       	  if ($k->getEstado() != 1) 
                                                                                                                                                                                          echo '<option value="'.$k->getIdUsuario().'">'.$k->getNombreUsuario().'</option>';
                                                                                                                                                                                          
                                                                                                                                                                                       }
                                                                                                                                                                                   endforeach;
                                                                                                                                                                             ?>   
                                                                                                                                                                              </select>&nbsp;&nbsp;<b>Etapa:<b/> <select id='search_et' onChange='doSearch(arguments[0]||event)' ><option></option> <?php 
                                                                                                                                                                                                                                                                                                        foreach ($estapa as $k):  
                                                                                                                                                                                                                                                                                                              if ($k->GetIdEtapa() == 4 || $k->GetIdEtapa() == 10 || $k->GetIdEtapa() == 11) 
                                                                                                                                                                                                                                                                                                                     echo '<option value="'.$k->GetIdEtapa().'">'.$k->GetNombre().'</option>'; 
                                                                                                                                                                                                                                                                                                        endforeach;
                                                                                                                                                                                                                                                                                                     ?> 
                                                                                                                                                                                                                                                                                                     </select> <b>Referencias:<b/> <input type='text' background='#ff22ff' id='search_cd' onkeydown='doSearch(arguments[0]||event)' style='height:13px;font-size:2;color:#ff00ff;' size='10'/></td>
    </tr>
<tr>
<td>
    <table id="list" class="scroll"></table>
    <div id="pager" class="scroll" style="text-align:center;"></div>
</td>
 </tr>
</table>
</div>